<?php //pack11class

class ObjectCardCurrency extends Module {

    public function setup() {
        $this->addChild($this->generateCurrencySelect());
    }

    private function generateCurrencySelect() {
        $select=new SelectInput;
        $currencies=CurrencyManager::getCurrencies();
        if(!$currencies) {
            return "";
        }

        $curren=SettingsManager::getSetting("currency");
        $obj=SettingsManager::getSetting("object");

        foreach($currencies as $currency) {
            $option=new SelectOption;
            $option->label=$currency->label;

            $queryObject=new GetQueryObject();
            $c=clone $curren;
            $c->value=$currency->id;
            $queryObject->setValue($c, GetQueryObject::SETTING);
            $queryObject->setValue($obj, GetQueryObject::SETTING);

            $option->value=GetQuery::generate($queryObject);
            $option->selected=($currency==CurrencyManager::currentCurrency())? SelectOption::SELECTED:"";
            $select->addChild($option);
        }


        $select->property_name="currency";
        $select->setID("ObjectCard_currency");
        $select->events=str_replace('\"', '"', "onChange=\"ObjectCard.setCurrency(this);\"");
        $select->class="select";
        $select->setClass("ObjectCard_currency");
        $select->lamp_class="hidden";
        return $select;
    }

}
?>
